package com.ruoyi.framework.controller;

import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
import com.ruoyi.common.core.result.Result;
import com.ruoyi.framework.web.domain.Server;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 服务器监控
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/monitor/server")
public class ServerController {

    @Autowired
    private DruidStatProperties druidStatProperties;

    @PreAuthorize("@ss.hasPermi('monitor:server:list')")
    @GetMapping()
    public Result<Server> getInfo() throws Exception {
        Server server = new Server();
        server.copyTo();
        return Result.success(server);
    }

    @PreAuthorize("@ss.hasPermi('monitor:server:list')")
    @GetMapping("/druidPwd")
    public Result<DruidStatProperties.StatViewServlet> druidPwd() {
        DruidStatProperties.StatViewServlet viewServlet = druidStatProperties.getStatViewServlet();
        return Result.success(viewServlet);
    }
}
